<!DOCTYPE html>
<script type="text/javascript" src="/js/jquery-3.5.1.min.js"></script>

<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<script type="text/javascript">
    function getEmailCode() {
        var email= $("#emailTxt").val();
        if(email!=""){
            $.ajax({
                url:"/user/getEmailCode",
                type:"post",
                data:"email="+email,
                success:function (msg) {
                    if(msg=="1"){
                        alert("验证码已发送")
                    }else{
                        alert("网络繁忙")
                    }
                }
            });
        }else{
            alert("请输入邮箱")
        }
    }
    function login() {
        location.href="/user/reindex";
    }
    function checkName() {
        var nameValue = $("#nameTxt").val();
        $.ajax({
            url : "/user/checkName",
            type : "post",
            data : "userName=" + nameValue,
            success : function(result) {
                if (result == 1) {

                } else {
                    alert("用户名已存在");
                    location.href = "/user/relogin";
                }
            }
        });
    }
</script>
<body>
<form action="/user/reg" method="post">

    <input type="text" name="userName"
           id="nameTxt"  placeholder="请输入用户名" onblur="checkName()">
    </br>

    <input type="password" name="passWord"
           placeholder="请输入密码">
    </br>
    <input type="date" name="birth"
           placeholder="请输入生日" >
    </br>


    邮箱：<input type="text" id="emailTxt" name="email"/>
    </br>
    验证码：<input type="text" name="emailCode"/><a href="javaScript:void(0)" onclick="getEmailCode()">获取验证码</a>
    </br>
    <input type="submit" value="注册" >
    <input type="button" value="去登录" onclick="login()">

</form>
</body>
</html>